<?php

die('nix gibts');
exit;
exit;

error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', 'On');

include ('../_config.inc.php');
$out = "";

error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', 'On');



if (isset($_POST) && trim($_POST['q']) != '') {
   
    // SELECT u.f_key AS Number, u.email AS Email, p.name AS Name, m.f_key AS email_mail
    //   FROM  `email` m
    //   LEFT JOIN persons p ON ( p.f_key = m.owner ) 
    //   LEFT JOIN users u ON ( u.f_key = m.owner ) 
    //   WHERE m.owner =  '431853'
    //   LIMIT 0 , 30
    // $db->unbuffered_query($insert);
    
    $results = array();
    $select = "SELECT * FROM `users` WHERE `f_key` LIKE '%".lico_ESC($_POST['q'])."%' OR `email` LIKE '%".lico_ESC($_POST['q'])."%'";
    $ret = $db->getAll_assoc($select);
  	for ($a=0; $a<count($ret); $a++) {
  		$f_key = intval($ret[$a]['f_key']);
  		$email = trim($ret[$a]['email']);
  		$city = trim($ret[$a]['city']);
  		$country = trim($ret[$a]['country']);
  		$state = intval($ret[$a]['state']);
  		$name = '';
      $results['f_key'][] = $f_key;
      $results['email'][] = $email;
      $results['name'][] = $name;
      $results['city'][] = $city;
      $results['country'][] = $country;
      $results['state'][] = $state;
      $results['table'][] = 'users';
    }
   
    $select = "SELECT * FROM `persons` WHERE `f_key` LIKE '%".lico_ESC($_POST['q'])."%' OR `name` LIKE '%".lico_ESC($_POST['q'])."%'";
    $ret = $db->getAll_assoc($select);
  	for ($a=0; $a<count($ret); $a++) {
  		$f_key = intval($ret[$a]['f_key']);
  		$email = trim($ret[$a]['email']);
  		$city = trim($ret[$a]['city']);
  		$country = trim($ret[$a]['country']);
  		$state = intval($ret[$a]['state']);
  		$name = trim($ret[$a]['name']);
      $results['f_key'][] = $f_key;
      $results['email'][] = $email;
      $results['name'][] = $name;
      $results['city'][] = $city;
      $results['country'][] = $country;
      $results['state'][] = $state;
      $results['table'][] = 'persons';
    }
   
    $select = "SELECT * FROM `email` WHERE `f_key` LIKE '%".lico_ESC($_POST['q'])."%' OR `owner` LIKE '%".lico_ESC($_POST['q'])."%'";
    $ret = $db->getAll_assoc($select);
  	for ($a=0; $a<count($ret); $a++) {
  		$f_key = intval($ret[$a]['owner']);
  		$email = trim($ret[$a]['f_key']);
  		$city = trim($ret[$a]['city']);
  		$country = trim($ret[$a]['country']);
  		$state = intval($ret[$a]['state']);
  		$name = trim($ret[$a]['name']);
      $results['f_key'][] = $f_key;
      $results['email'][] = $email;
      $results['name'][] = $name;
      $results['city'][] = $city;
      $results['country'][] = $country;
      $results['state'][] = $state;
      $results['table'][] = 'email';
    }
   
   
}
?><html>
<head>
      <title> Find and manage users </title>
</head>
<body>

  <div id="findform">
    <form name="findform" action="./find.php" method="post">
      <div id="searchfield">
        <input type="text" name="q" value="<?php echo $_POST['q']; ?>"/>
      </div>
      <div id="searchsubmit">
        <input type="submit" name="submit" value="Search..."/>
      </div>
    </form>
  </div>
  
  
  
  
  
  <?php
  echo '<br><br><br><br><pre>';
  print_r($results);
  echo '</pre>';
  ?>
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  

</body>
</html>